@echo off
rem 不能重命名文件夹
rem 可以替换一部分文件名,例如删除开头的字符串那么new filename就直接回车
echo WARNING: Please make a backup before executing this batch file.
:askSubfolders
set /p includeSubfolders=Do you want to include subfolders? (y/n):
if /i "%includeSubfolders%"=="y" goto startProcessing
if /i "%includeSubfolders%"=="n" goto startProcessing
echo Invalid input. Please enter y or n.
goto askSubfolders

:startProcessing
set /p oldStr=Enter the starting string of the file name to be replaced:
set /p newStr=Enter the new file name:
setlocal enabledelayedexpansion

if /i "%includeSubfolders%"=="y" (
    for /r %%d in (.) do (
        for %%f in ("%%d\%oldStr%*") do (
            set "oldname=%%~nxf"
            set "newname=!oldname:%oldStr%=%newStr%!"
            ren "%%f" "!newname!"
        )
    )
) else (
    for %%f in ("%oldStr%*") do (
        set "oldname=%%~nxf"
        set "newname=!oldname:%oldStr%=%newStr%!"
        ren "%%f" "!newname!"
    )
)

echo File name batch modification completed.
pause